package com.person.download.service.impl;

import java.util.List;

import com.person.commons.utils.DAO;
import com.person.commons.utils.FlipPageInfo;
import com.person.download.model.Download;
import com.person.download.service.DownloadService;
import com.person.link.model.Link;
import com.person.title.model.TitleFunc;


public class DownloadServiceImpl implements DownloadService{
	
	private DAO dao;
	

	/**
	 * 用于保存下载模块的文件添加
	 */
	public void saveDownload(Download download){
		
		dao.save(download);
	}
	/**
	 * 查找下载管理模块的所有文件信息，列表出来
	 */
	public FlipPageInfo findAllDownloadFile(FlipPageInfo fpi){
		
		return dao.findWithPaging("select t.funcName,d.downHead,d.downName,d.downSize,d.downDown,d.downId " +
				"from Download d,TitleFunc t where d.funcId=t.funcId order by d.funcId,d.downName", fpi);
	}
	/**
	 * 删除Download对象
	 */
	public void deleteDownload(Download download){
		
		dao.delete(download);
	}
	/**
	 * 通过文件标题或者文件名来查询，列表出来
	 */
	public FlipPageInfo findDownloadFileByInfo(String hql,FlipPageInfo fpi){
		
		return dao.findWithPaging(hql, fpi);
	}
	/**
	 * 通过downId查找Download对象
	 */
	public Download findDownloadBydownId(String downId){
		
		List lt = dao.find("from Download where downId='"+downId+"'");
		if(lt.size()>0){
			return (Download) lt.get(0);
		}else{
			return new Download();
		}
	}
	/**
	 * 更新修改后的Download对象
	 */
	public void updateDownload(Download download){
		
		dao.update(download);
	}
	
	/**
	 * 根据funcId从栏目功能表TitleFunc查找功能名
	 */
	public TitleFunc findTitleFuncByFuncId(String funcId){
		try{
			return (TitleFunc) dao.find(TitleFunc.class, funcId);
		}catch(Exception e){
			System.out.println("栏目功能表TitleFunc查找功能名出现异常");
		}
		return new TitleFunc();
	}

	/**
	 * 根据funcId查找Download
	 */
	public List<Download> findDownloadByFuncId(String funcId) {
		
		return dao.find("from Download where funcId='"+funcId+"'  order by downId desc") ;
	}	

	/**
	 * 查找下载信息，分页列表
	 * @param fpi
	 * @return
	 */
	public FlipPageInfo findDownloadByInfo (String funcId ,FlipPageInfo fpi) {
		return this.dao.findWithPaging("from Download where funcId='"+funcId+"' order by downId desc", fpi) ;
	}
	
	
	/**
	 * @return the dao
	 */
	public DAO getDao() {
		return dao;
	}
	/**
	 * @param dao the dao to set
	 */
	public void setDao(DAO dao) {
		this.dao = dao;
	}
	
}